package com.didispace;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionListener;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.Connection;

public class MyConnectionFactory implements ConnectionFactory{
	protected Random random = new Random(System.currentTimeMillis());
	List<CachingConnectionFactory>connectionFactoryList = new ArrayList<>();
	public MyConnectionFactory(List<CachingConnectionFactory>connectionFactoryList) {
		this.connectionFactoryList = connectionFactoryList;
	}
	@Override
	public Connection createConnection() throws AmqpException {
		int addSize = connectionFactoryList.size();
		int randomIndex = random.nextInt(addSize);
		return connectionFactoryList.get(randomIndex).createConnection();
	}
	@Override
	public String getHost() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public int getPort() {
		// TODO Auto-generated method stub
		return 0;
	}
	@Override
	public String getVirtualHost() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public String getUsername() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void addConnectionListener(ConnectionListener listener) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public boolean removeConnectionListener(ConnectionListener listener) {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public void clearConnectionListeners() {
		// TODO Auto-generated method stub
		
	}
}
